package com.caifu.controller;

import com.caifu.bean.Result;
import com.caifu.bean.ResultUtil;
import com.caifu.pojo.SysMenu;
import com.caifu.pojo.SysUser;
import com.caifu.service.SysMenuService;
import net.sf.json.JSONArray;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author tww
 * ClassName: SysMenuController.java、
 * createTime: 2021年03月02日 15:16:44
 **/
@Controller
@RequestMapping("menu")
public class SysMenuController extends AbstractController {

    @Resource
    private SysMenuService sysMenuService;

    /**
     * 根据用户id获取用户菜单
     *
     * @param id 父菜单id
     * @return
     */
    @GetMapping("getMenus")
    @ResponseBody
    public Result getMenus(Integer id) {
        SysUser sysUser = getSysUser();
        List<SysMenu> menus = sysMenuService.getMenus(id,sysUser);
        System.out.println(JSONArray.fromObject(menus).toString(2));
        return ResultUtil.getDataSuccess(menus);
    }


    /**
     * 获取所有菜单资源
     *
     * @return
     */
    @GetMapping("getAllMenus")
    @ResponseBody
    public Result getAllMenus() {
        List<SysMenu> menus = sysMenuService.getAllMenus();
        return ResultUtil.getDataSuccess(menus);
    }

}
